﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Data;
using System.Globalization;

namespace BadHabit.Factory.Converters {

    [ValueConversion(typeof(string), typeof(Data.ProjectDataSet.BacklogItemUnitRow))]
    public class UnitNameConverter :IValueConverter {

        public static Data.ProjectDataSet.BacklogItemUnitDataTable UnitList { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            String unitName = value as String;            

            if (unitName == null)
                return null;

            if (UnitList == null || UnitList.Count==0)
                return null;

            string projectUId = UnitList[0].ProjectUId;
            Data.ProjectDataSet.BacklogItemUnitRow unit = UnitList.FindByUnitNameProjectUId(unitName, projectUId);
            if (unit == null)
                return null;

            

            return unit;


        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return new NotSupportedException();
        }



    }
}
